<template>
  <div class="qingwu">
    <div class="admin_main_block">
      <div class="admin_main_block_top">
        <div class="admin_main_block_left">
          <div>
            <router-link to="/Admin/adv/form">
              <el-button type="primary" icon="el-icon-plus">添加</el-button>
            </router-link>
          </div>
          <!-- <div><el-input v-model="name" placeholder="请输入内容"></el-input></div>
                    <div><el-button icon="el-icon-search">条件筛选</el-button></div> -->
        </div>

        <!-- <div class="admin_main_block_right">
          <div>
            <el-button type="danger" icon="el-icon-delete" @click="del(select_id)">批量删除</el-button>
          </div>
        </div> -->
      </div>
      <div class="admin_table_main">
        <el-table :data="list" @selection-change="handleSelectionChange">
          <!-- <el-table-column type="selection"></el-table-column> -->
          <!-- <el-table-column prop="id" label="#" fixed="left" width="70px"></el-table-column> -->
          <el-table-column label="序号" width="50px">
            <template slot-scope="scope">
              <div>{{scope.$index+1}}</div>
            </template>
          </el-table-column>
          <el-table-column prop="adv_title" label="广告名称" width="120px"></el-table-column>
          <!-- <el-table-column prop="adv_sort" label="广告位置" width="150px"></el-table-column> -->
          <el-table-column label="展示图片">
            <template slot-scope="scope">
              <dl class="table_dl">
                <dt><img :src="scope.row.adv_image||require('@/assets/default_pic.png')" width="50px" height="50px"></dt>
              </dl>
            </template>
          </el-table-column>
          <el-table-column prop="adv_type_name" label="跳转类型"></el-table-column>
          <el-table-column prop="adv_link" label="跳转链接" width="150px"></el-table-column>
          <el-table-column prop="adv_sort" label="排序" width="50px"></el-table-column>
          <el-table-column prop="adv_start" label="开始时间" width="90px">
            <template slot-scope="scope">
              <div v-if="scope.row.adv_start<=0"> - </div>
              <div v-else>{{scope.row.adv_start|formatDate}}</div>
            </template>
          </el-table-column>
          <el-table-column prop="adv_end" label="结束时间" width="90px">
            <template slot-scope="scope">
              <div v-if="scope.row.adv_end<=0"> - </div>
              <div v-else>{{scope.row.adv_end|formatDate}}</div>
            </template>
          </el-table-column>
          <el-table-column label="操作" fixed="right" width="150px">
            <template slot-scope="scope">
              <el-button size="mini" type="primary" @click="$router.push({name:'adv_form',params:{id:scope.row.id}})">编辑</el-button>
              <el-button size="mini" type="danger" @click="del(scope.row.id)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="admin_table_main_pagination">
          <el-pagination @current-change="current_change" background layout="prev, pager, next,jumper,total" :total="total_data"
            :page-size="page_size" :current-page="current_page"></el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  components: {},
  props: {},
  data() {
    return {
      list: [],
      total_data: 0, // 总条数
      page_size: 20,
      current_page: 1,
      select_id: '',
      adv_position_id: 0,
    };
  },
  watch: {},
  computed: {},
  methods: {
    handleSelectionChange: function (e) {
      let ids = [];
      e.forEach(v => {
        ids.push(v.id);
      });
      this.select_id = ids.join(',');
    },
    get_adv_list: function () {
      if (!this.$isEmpty(this.$route.params.adv_position_id)) {
        this.adv_position_id = this.$route.params.adv_position_id;
      }
      this.$get(this.$api.getAdvList, { page: this.current_page, adv_position_id: this.adv_position_id }).then(res => {
        this.page_size = res.data.per_page;
        this.total_data = res.data.total;
        this.current_page = res.data.current_page;
        this.list = res.data.data;
      })

    },
    // 删除处理
    del: function (id) {
      if (this.$isEmpty(id)) {
        return this.$message.error('请先选择删除的对象');
      }
      this.$post(this.$api.delAdv, { id: id }).then(res => {
        if (res.code == 200) {
          this.get_adv_list();
          return this.$message.success("删除成功");
        } else {
          return this.$message.error("删除失败");
        }
      });
    },
    current_change: function (e) {
      this.current_page = e;
      this.get_adv_list();
    },
  },
  created() {},
  mounted() { 
    this.get_adv_list();
  }
};
</script>
<style lang="scss" scoped>
</style>